How to split a string by ',' or '[|]' unless the ',' is in '{}'
Posted
by floyddotnet
on Stack Overflow
See other posts from Stack Overflow
or by floyddotnet
Published on 2010-03-18T17:12:57Z
Indexed on
2010/03/18
17:21 UTC
Read the original article
Hit count: 518
regex
|JavaScript
i search for a regex to split the following string:
aaa[bbb,ccc[ddd,{eee:1,mmm:999}],nnn[0,3]]
aaa[bbb,ccc[ddd,{eee:1, mmm:[123,555]}],nnn[0,3]]
aaa[bbb, ccc[ddd, ddd],nnn[0,3]]
aaa[bbb,ddd[0,3]]
by '[' or ']' or ',' unless the ',' is in '{}'. As example: split 'aaa[bbb,ccc[ddd,' to aaa, bbb, ccc, ddd is allow but not {eee:1,mmm:999}.
the result:
aaa, bbb, ccc, ddd, {eee:1,mmm:999}, nnn, 0, 3
aaa, bbb, ccc, ddd, {eee:1, mmm:[123,555]}], nnn, 0, 3
aaa, bbb, ccc, ddd, ddd, nnn, 0, 3
aaa, bbb, ddd, 0, 3
i have read meany other questions but i cant modifie the regex's there are post to do this what i want.
the target language for the expression is javascript.
© Stack Overflow or respective owner